from sqlalchemy import Column, Integer, String, DateTime, Text
from sqlalchemy.sql import func
from app.database import Base


class UnitView(Base):
    """设备视图模型"""

    __tablename__ = "unit_views"

    id = Column(Integer, primary_key=True, index=True)
    sn_code = Column(String(100), unique=True, index=True, nullable=False, comment="SN码")
    top_view = Column(Text, nullable=True, comment="上方位")
    bottom_view = Column(Text, nullable=True, comment="下方位")
    left_view = Column(Text, nullable=True, comment="左方位")
    right_view = Column(Text, nullable=True, comment="右方位")
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())

    def __repr__(self):
        return f"<UnitView(id={self.id}, sn_code='{self.sn_code}')>"